#include <X11/Xlib.h>
#include <iostream>
int main() {
  Display *display = nullptr;
  Window window;
  XEvent event;
  std::string msg = "goldfish test";

  display = XOpenDisplay(nullptr);
  if (display == nullptr) {
    std::cerr << "Cannot open display\n";
    return 1;
  }
  int s = DefaultScreen(display);
  window =
      XCreateSimpleWindow(display, RootWindow(display, s), 10, 10, 200, 200, 1,
                          BlackPixel(display, s), WhitePixel(display, s));
  //                           BlackPixel(display, s), WhitePixel(display, s));
  ;
  XSelectInput(display, window, ExposureMask | KeyPressMask);
  XMapWindow(display, window);
  while (true) {
    XNextEvent(display, &event);
    printf("event type:%d\n",event.type);
    switch (event.type) {
    case Expose:
      XFillRectangle(display, window, DefaultGC(display, s), 20, 20, 10, 10);
      XDrawString(display, window, DefaultGC(display, s), 50, 50, msg.c_str(),
                  msg.size());
      break;
    case KeyPress:
      XCloseDisplay(display);
      return 0;
    default:
      break;
    }
  }
  // return 0;
}
